package cn.vc.content.service.video;

import cn.vc.content.entity.video.VideoCoins;
import cn.vc.content.mapper.video.VideoCoinsMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VideoCoinsService {

    @Autowired
    private VideoCoinsMapper videoCoinsMapper;



    public boolean coins(Long id, Long userId, Long coins) {
        LambdaQueryWrapper<VideoCoins> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VideoCoins::getVideoId, id).eq(VideoCoins::getUserId, userId);
        VideoCoins videoCoins = videoCoinsMapper.selectOne(lqw);
        // 以及给该视频投过币，不可重复投币
        if (videoCoins != null) return false;
        videoCoins = new VideoCoins();
        videoCoins.setVideoId(id);
        videoCoins.setUserId(userId);
        videoCoins.setCoins(coins.intValue());
        return videoCoinsMapper.insert(videoCoins)==1;
    }
}
